<?php
/**
 * +----------------------------------------------------------------------
 * | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
 * +----------------------------------------------------------------------
 * | File name: BbpPlatformRequest.php
 * +----------------------------------------------------------------------
 * | Author: sam
 * +----------------------------------------------------------------------
 * | Description: 用于详细说明此程序文件完成的主要功能，与其他模块或函数的接口、输出值、取值范围、含义及参数间的控制、顺序或依赖等关系。
 * +----------------------------------------------------------------------
 * | Others: 其他内容的说明
 * +----------------------------------------------------------------------
 * | History: 修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简述
 * +----------------------------------------------------------------------
 * | 1.Date: 2019/1/15 Author: sam Modification: 创建
 * +----------------------------------------------------------------------
 */

namespace App\Library\Guzzle;


use GuzzleHttp\Client;

class BbpPlatformRequest
{
    /**
     * Description:申请商城token
     * Author: Sam
     * DateTime: 2019/1/15 16:11
     * @param $phone
     * @param $userId
     * @return mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function syncUser($phone,$userId)
    {
        $url = 'user/synUser';
        $body = [
            "cardId"=>"",
            "nsfpUserID"=>"",
            "outUserId"=>"$userId",
            "phone"=>"$phone",
            "token"=>"",
            "tokenExpireTime"=>"",
        ];
        $client = new Client(['base_uri'=>config('common.bbp_platform_base_uri'),'timeout'=>30.0]);
        $result = $client->request("POST",$url,['json'=>$body,'verify'=>false]);
        return json_decode($result->getBody()->getContents(), true);
    }

    /**
     * Description:检查token有效性
     * Author: Sam
     * DateTime: 2019/1/15 16:53
     * @param $token
     * @return mixed
     */
    public static function checkToken($token)
    {
        $url = config('common.bbp_platform_base_uri')."/user/checkToken/$token";
        $client = new Client();
        $result = $client->get($url,['verify'=>false]);
        return json_decode($result->getBody()->getContents(), true);
    }

    /**
     * Description:根据user_id获取token
     * Author: Sam
     * DateTime: 2019/1/15 16:56
     * @param $user_id
     * @return mixed
     */
    public static function getTokenByUserId($user_id)
    {
        $url = config('common.bbp_platform_base_uri')."/user/getToken/$user_id";
        $client = new Client(['base_uri'=>config('common.bbp_platform_base_uri'),'verify'=>false]);
        $result = $client->get($url);
        return json_decode($result->getBody()->getContents(), true);
    }
}